﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace cmdLineParserModule.HelperClasses
{
    /// <summary>
    /// Provides interface for text work with choices
    /// </summary>
    internal static class ChoiceTextManager
    {
        /// <summary>
        /// Removes choice prefix from string if there is any
        /// </summary>
        /// <param name="argument">Text with prefix</param>
        /// <returns></returns>
        internal static string removeChoicePrefix(string argument)
        {
            if (argument.Equals(ParserConsts.ARGUMENT_SEPARATOR))
                return argument;
            else if (argument.StartsWith(ParserConsts.CHOICESTARTLONG))
                return argument.Substring(ParserConsts.CHOICESTARTLONG.Length);
            else if (argument.StartsWith(ParserConsts.CHOICESTARTSHORT))
                return argument.Substring(ParserConsts.CHOICESTARTSHORT.Length);
            else return argument;
        }

        /// <summary>
        /// Checks if given argument consits of alpha characters only
        /// </summary>
        /// <param name="argument">Candidate for choice</param>
        /// <returns></returns>
        internal static bool fitsChoicePattern(string argument)
        {
            string unprefixedArgument = removeChoicePrefix(argument);
            return new Regex("[a-zA-Z]+").Match(unprefixedArgument).Length == unprefixedArgument.Length;
        }

        /// <summary>
        /// Adds choice prefix to argument
        /// </summary>
        /// <param name="argument">Text to add prefix to</param>
        /// <returns></returns>
        internal static string addChoicePrefix(string argument)
        {
            if (argument == null)
            {
                return "<command not defined!>";
            }

            if (argument.Length == 1)
                return ParserConsts.CHOICESTARTSHORT + argument;
            else
                return ParserConsts.CHOICESTARTLONG + argument;
        }



    }
}
